<?php
include dirname(dirname(__FILE__)).'/functions.php';
include_once dirname(dirname(dirname(dirname(__FILE__)))).'/include/host-base.php';
$uploaddir = dirname(dirname(dirname(dirname(__FILE__)))).'/images/';//设置文件保存目录 注意包含/
$type=array("jpg","gif","bmp","jpeg","png");//设置允许上传文件的类型
$res["error"] ="";//错误信息
$res["msg"] ="";//提示信息



if (!empty($_FILES)) {
	
	$a=strtolower(fileext($_FILES['image']['name']));
	//判断文件类型
	if(!in_array(strtolower(fileext($_FILES['image']['name'])),$type))
	{
	$res["error"] = "error";
	}else{
		$filename=explode(".",$_FILES['image']['name']);
		do{
				$filename[0]=random(10); //设置随机数长度
				$name=implode(".",$filename);
				$uploadfile=$uploaddir.$name;
			}while(file_exists($uploadfile));
		if (move_uploaded_file($_FILES['image']['tmp_name'],$uploadfile)){
			
			$url=getHost()."/images/".$name;
			$res["msg"] = "ok";
			$res["url"]=$url;
			$res["storeName"]=$name;
		}else{
			$res["error"] = "error";
			
			}
	}
}
echo json_encode($res);

?>